home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / StarsText / StarsText.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  13.1 KB  |  665 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Cursor;
  8. import java.awt.Font;
  9. import java.awt.FontMetrics;
  10. import java.awt.Graphics;
  11. import java.awt.Image;
  12. import java.awt.MediaTracker;
  13. import java.awt.Scrollbar;
  14. import java.awt.event.AdjustmentEvent;
  15. import java.awt.event.AdjustmentListener;
  16. import java.awt.event.MouseEvent;
  17. import java.awt.event.MouseListener;
  18. import java.net.MalformedURLException;
  19. import java.net.URL;
  20. import java.net.URLEncoder;
  21.  
  22. public class StarsText extends Applet implements Runnable, AdjustmentListener, MouseListener {
  23.    private Thread thread;
  24.    private Image backImage;
  25.    private Image buffer;
  26.    // $FF: renamed from: b java.awt.Graphics
  27.    private Graphics field_0;
  28.    private boolean loaded;
  29.    private boolean move = true;
  30.    // $FF: renamed from: on boolean
  31.    private boolean field_1 = true;
  32.    private boolean firstime = true;
  33.    private boolean isBackImage = false;
  34.    private boolean paintable = false;
  35.    private boolean zoomable = true;
  36.    private int text_height;
  37.    private int current_height;
  38.    private int height_step;
  39.    private int height_step2;
  40.    private int letter_width;
  41.    private int letter_width_100;
  42.    private int letter_ascent;
  43.    private int letter_ascent_100;
  44.    // $FF: renamed from: wi int
  45.    private int field_2;
  46.    // $FF: renamed from: he int
  47.    private int field_3;
  48.    private int wiBack;
  49.    private int heBack;
  50.    private int pause;
  51.    private int number;
  52.    // $FF: renamed from: X int[]
  53.    private int[] field_4;
  54.    // $FF: renamed from: Y int[]
  55.    private int[] field_5;
  56.    private int[] step;
  57.    private int decx;
  58.    private int decy;
  59.    // $FF: renamed from: x int
  60.    private int field_6;
  61.    // $FF: renamed from: y int
  62.    private int field_7;
  63.    private int decX;
  64.    // $FF: renamed from: l int
  65.    private int field_8;
  66.    private int[] index;
  67.    private int n_text;
  68.    private int step_mean;
  69.    private String letter;
  70.    private String backImageName;
  71.    private String text;
  72.    private String big_text;
  73.    private Color starColor;
  74.    private Color backColor;
  75.    // $FF: renamed from: fm java.awt.FontMetrics
  76.    private FontMetrics field_9;
  77.    private Scrollbar scroll;
  78.    private int pause_init;
  79.    private boolean isScrollbar;
  80.    private String statusBarText;
  81.    private AudioClip sound;
  82.    private AudioClip clicSound;
  83.    private AudioClip enterSound;
  84.    private boolean loopSound;
  85.    private String link;
  86.    private FontMetrics fm2;
  87.    private String enterText;
  88.    private boolean isEnterTextEnabled;
  89.    private int wiEnterText;
  90.    private int enterTextHeight;
  91.    private Color enterTextColor;
  92.    private Font bufferFont;
  93.    private Font textFont;
  94.  
  95.    public String getAppletInfo() {
  96.       return "Name: StarsText\r\nAuthor: Taiji Software\r\n";
  97.    }
  98.  
  99.    public StarsText() {
  100.       this.move = true;
  101.       this.number = 100;
  102.       this.text_height = 10;
  103.       this.height_step = 2;
  104.       this.height_step2 = 2;
  105.       this.isScrollbar = false;
  106.       this.pause = 20;
  107.       ((Component)this).addMouseListener(this);
  108.    }
  109.  
  110.    public void register() {
  111.       try {
  112.          URL u = new URL("http://www.taijisoftware.com");
  113.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  114.       } catch (Exception e) {
  115.          System.out.println(e);
  116.          this.stop();
  117.       }
  118.    }
  119.  
  120.    public void init() {
  121.       String codeBase = null;
  122.  
  123.       try {
  124.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  125.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  126.          codeBase = codeBase.toUpperCase();
  127.       } catch (Exception var9) {
  128.       }
  129.  
  130.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  131.          String regCode = ((Applet)this).getParameter("registration_code");
  132.          if (regCode == null) {
  133.             regCode = ((Applet)this).getParameter("reg_domain");
  134.             if (regCode == null) {
  135.                this.register();
  136.             } else {
  137.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  138.                   codeBase = "WWW." + codeBase;
  139.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  140.                   codeBase = codeBase.substring(4);
  141.                }
  142.  
  143.                char[] chars = new char[codeBase.length()];
  144.                codeBase.getChars(0, codeBase.length(), chars, 0);
  145.                String key = new String("haricot");
  146.                char[] chars2 = new char[key.length()];
  147.                key.getChars(0, key.length(), chars2, 0);
  148.  
  149.                for(int i = 0; i < codeBase.length(); ++i) {
  150.                   int j;
  151.                   if (i >= key.length()) {
  152.                      j = i - key.length() * (i / key.length());
  153.                   } else {
  154.                      j = i;
  155.                   }
  156.  
  157.                   chars[i] += chars2[j];
  158.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  159.                }
  160.  
  161.                String res = new String(chars);
  162.                if (!res.equalsIgnoreCase(regCode)) {
  163.                   this.register();
  164.                }
  165.             }
  166.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  167.             this.register();
  168.          }
  169.       }
  170.  
  171.       this.getParameters();
  172.       this.scroll = new Scrollbar(1, 30, 1, 0, 60);
  173.       this.scroll.addAdjustmentListener(this);
  174.       if (this.isScrollbar) {
  175.          ((Container)this).setLayout(new BorderLayout());
  176.          ((Container)this).add("East", this.scroll);
  177.       }
  178.  
  179.       if (this.sound != null) {
  180.          if (this.loopSound) {
  181.             this.sound.loop();
  182.             return;
  183.          }
  184.  
  185.          this.sound.play();
  186.       }
  187.  
  188.    }
  189.  
  190.    public void getParameters() {
  191.       this.field_2 = ((Component)this).getSize().width;
  192.       this.field_3 = ((Component)this).getSize().height;
  193.       if (this.isScrollbar) {
  194.          this.field_2 -= this.scroll.getSize().width;
  195.       }
  196.  
  197.       String s = ((Applet)this).getParameter("pause");
  198.       if (s != null) {
  199.          this.pause = Integer.parseInt(s);
  200.       }
  201.  
  202.       this.pause_init = this.pause;
  203.       s = ((Applet)this).getParameter("number");
  204.       if (s != null) {
  205.          this.number = Integer.parseInt(s);
  206.       }
  207.  
  208.       this.big_text = ((Applet)this).getParameter("text");
  209.       s = ((Applet)this).getParameter("text_height");
  210.       if (s != null) {
  211.          this.text_height = Integer.parseInt(s);
  212.       }
  213.  
  214.       s = ((Applet)this).getParameter("step_mean");
  215.       if (s != null) {
  216.          this.step_mean = Integer.parseInt(s);
  217.       } else {
  218.          this.step_mean = this.field_2 / 10;
  219.       }
  220.  
  221.       s = ((Applet)this).getParameter("height_step");
  222.       if (s != null) {
  223.          this.height_step = Integer.parseInt(s);
  224.       }
  225.  
  226.       s = ((Applet)this).getParameter("height_step2");
  227.       if (s != null) {
  228.          this.height_step2 = Integer.parseInt(s);
  229.       }
  230.  
  231.       s = ((Applet)this).getParameter("scrollbar");
  232.       if (s != null) {
  233.          this.isScrollbar = new Boolean(s);
  234.       }
  235.  
  236.       this.starColor = this.getColor("star_color");
  237.       if (this.starColor == null) {
  238.          this.starColor = Color.white;
  239.       }
  240.  
  241.       this.backColor = this.getColor("background_color");
  242.       if (this.backColor == null) {
  243.          this.backColor = Color.black;
  244.       }
  245.  
  246.       ((Component)this).setBackground(this.backColor);
  247.       this.backImageName = ((Applet)this).getParameter("background_image");
  248.       if (this.backImageName != null) {
  249.          this.isBackImage = true;
  250.       }
  251.  
  252.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  253.       s = ((Applet)this).getParameter("sound_name");
  254.       if (s != null) {
  255.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  256.       }
  257.  
  258.       s = ((Applet)this).getParameter("loop_sound");
  259.       if (s != null) {
  260.          if (s.equals("yes")) {
  261.             this.loopSound = true;
  262.          } else {
  263.             this.loopSound = false;
  264.          }
  265.       }
  266.  
  267.       s = ((Applet)this).getParameter("clic_sound_name");
  268.       if (s != null) {
  269.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  270.       }
  271.  
  272.       s = ((Applet)this).getParameter("enter_sound_name");
  273.       if (s != null) {
  274.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  275.       }
  276.  
  277.       this.link = ((Applet)this).getParameter("link");
  278.       this.enterText = ((Applet)this).getParameter("enter_text");
  279.       s = ((Applet)this).getParameter("enter_text_height");
  280.       if (s != null) {
  281.          this.enterTextHeight = Integer.parseInt(s);
  282.       }
  283.  
  284.       this.enterTextColor = this.getColor("enter_text_color");
  285.       if (this.enterTextColor == null) {
  286.          this.enterTextColor = Color.white;
  287.       }
  288.  
  289.    }
  290.  
  291.    public Color getColor(String param) {
  292.       String s = ((Applet)this).getParameter(param);
  293.       if (s != null) {
  294.          if (s.substring(0, 1).equals("#")) {
  295.             s = s.substring(1);
  296.             int i = Integer.parseInt(s, 16);
  297.             return new Color(i);
  298.          } else {
  299.             return null;
  300.          }
  301.       } else {
  302.          return null;
  303.       }
  304.    }
  305.  
  306.    public void adjustmentValueChanged(AdjustmentEvent e) {
  307.       int v = this.scroll.getValue() - 30;
  308.       float f = (float)v;
  309.       if (f < 0.0F) {
  310.          f = 1.0F / f;
  311.       }
  312.  
  313.       this.pause = (int)((float)this.pause_init * f);
  314.       if (this.pause < 5) {
  315.          this.pause = 5;
  316.       }
  317.  
  318.    }
  319.  
  320.    public final void refonte(int h) {
  321.       this.field_0.setFont(new Font("TimesRoman", 1, h));
  322.       this.field_9 = this.field_0.getFontMetrics();
  323.    }
  324.  
  325.    public final void nextLetter() {
  326.       this.letter = this.text.substring(this.field_8, this.field_8 + 1);
  327.       this.refonte(this.text_height);
  328.       this.letter_width_100 = this.field_9.stringWidth(this.letter);
  329.       this.letter_ascent_100 = this.field_9.getAscent();
  330.       this.current_height = 2;
  331.       this.refonte(this.current_height);
  332.       this.letter_width = this.field_9.stringWidth(this.letter);
  333.       this.letter_ascent = this.field_9.getMaxAscent();
  334.    }
  335.  
  336.    public final void nextText() {
  337.       ++this.n_text;
  338.       if (this.n_text > this.index.length) {
  339.          this.text = this.big_text.substring(0, this.index[0]);
  340.          this.n_text = 0;
  341.       } else if (this.n_text == this.index.length) {
  342.          this.text = this.big_text.substring(this.index[this.n_text - 1] + 1);
  343.       } else {
  344.          this.text = this.big_text.substring(this.index[this.n_text - 1] + 1, this.index[this.n_text]);
  345.       }
  346.  
  347.       this.refonte(this.text_height);
  348.       this.decx = (this.field_2 - this.field_9.stringWidth(this.text)) / 2;
  349.       this.decy = (this.field_3 + this.field_9.getMaxAscent() - this.field_9.getMaxDescent()) / 2;
  350.       this.field_8 = 0;
  351.       this.decX = 0;
  352.    }
  353.  
  354.    public final void paint(Graphics g) {
  355.       if (this.paintable) {
  356.          this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  357.          if (this.isBackImage & this.loaded) {
  358.             this.field_0.drawImage(this.backImage, (this.field_2 - this.wiBack) / 2, (this.field_3 - this.heBack) / 2, this);
  359.          }
  360.  
  361.          if (this.zoomable) {
  362.             this.refonte(this.current_height);
  363.             this.letter_width = this.field_9.stringWidth(this.letter);
  364.             this.letter_ascent = this.field_9.getMaxAscent();
  365.             this.field_6 = (this.letter_width_100 - this.letter_width) / 2;
  366.             this.field_7 = (this.text_height - this.current_height) / 2 + this.letter_ascent - this.text_height;
  367.             this.field_0.drawString(this.letter, this.decx + this.decX + this.field_6, this.decy + this.field_7);
  368.          }
  369.  
  370.          if (!this.zoomable) {
  371.             this.refonte(this.current_height);
  372.             this.letter_width = this.field_9.stringWidth(this.text);
  373.             this.letter_ascent = this.field_9.getMaxAscent();
  374.             this.field_6 = (this.letter_width_100 - this.letter_width) / 2;
  375.             this.field_7 = (this.text_height - this.current_height) / 2 + this.letter_ascent - this.text_height;
  376.             this.field_0.drawString(this.text.substring(0, this.field_8), this.decx + this.field_6, this.decy + this.field_7);
  377.             this.current_height -= this.height_step2;
  378.             if (this.current_height <= this.height_step2) {
  379.                if (this.index != null) {
  380.                   this.nextText();
  381.                }
  382.  
  383.                this.refonte(this.text_height);
  384.                this.field_8 = 0;
  385.                this.decX = 0;
  386.                this.nextLetter();
  387.                this.zoomable = true;
  388.             }
  389.          }
  390.  
  391.          if (this.field_8 != 0 & this.zoomable) {
  392.             this.refonte(this.text_height);
  393.             this.field_0.drawString(this.text.substring(0, this.field_8), this.decx, this.decy);
  394.          }
  395.  
  396.          if (this.zoomable) {
  397.             this.current_height += this.height_step;
  398.          }
  399.  
  400.          if (this.current_height >= this.text_height & this.zoomable) {
  401.             if (this.field_8 == this.text.length() - 1) {
  402.                this.zoomable = false;
  403.                ++this.field_8;
  404.                this.current_height = this.text_height;
  405.                this.refonte(this.text_height);
  406.                this.letter_width_100 = this.field_9.stringWidth(this.text);
  407.                this.letter_ascent_100 = this.field_9.getAscent();
  408.             } else {
  409.                this.decX += this.letter_width_100;
  410.                ++this.field_8;
  411.                this.nextLetter();
  412.             }
  413.          }
  414.  
  415.          for(int i = 0; i < this.number; ++i) {
  416.             this.field_0.drawRect(this.field_4[i], this.field_5[i], 1, 1);
  417.          }
  418.  
  419.          if (this.isEnterTextEnabled) {
  420.             this.bufferFont = this.field_0.getFont();
  421.             this.field_0.setColor(this.enterTextColor);
  422.             this.field_0.setFont(this.textFont);
  423.             this.field_0.drawString(this.enterText, (this.field_2 - this.wiEnterText) / 2, this.field_3 / 2);
  424.             this.field_0.setColor(this.starColor);
  425.             this.field_0.setFont(this.bufferFont);
  426.          }
  427.  
  428.          g.drawImage(this.buffer, 0, 0, this);
  429.       }
  430.  
  431.    }
  432.  
  433.    public final void update(Graphics g) {
  434.       this.paint(g);
  435.    }
  436.  
  437.    public void start() {
  438.       if (this.thread == null) {
  439.          this.move = true;
  440.          this.thread = new Thread(this);
  441.          this.thread.start();
  442.       }
  443.  
  444.    }
  445.  
  446.    public void stop() {
  447.       if (this.thread != null) {
  448.          this.move = false;
  449.          this.thread = null;
  450.       }
  451.  
  452.       if (this.sound != null) {
  453.          this.sound.stop();
  454.       }
  455.  
  456.    }
  457.  
  458.    public void run() {
  459.       if (this.firstime) {
  460.          if (this.isBackImage) {
  461.             MediaTracker tracker = new MediaTracker(this);
  462.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  463.             tracker.addImage(this.backImage, 0);
  464.  
  465.             try {
  466.                tracker.waitForAll();
  467.                this.loaded = !tracker.isErrorAny();
  468.             } catch (InterruptedException var6) {
  469.                this.stop();
  470.             }
  471.  
  472.             if (!this.loaded) {
  473.                this.stop();
  474.                return;
  475.             }
  476.          }
  477.  
  478.          if (this.isBackImage) {
  479.             this.wiBack = this.backImage.getWidth(this);
  480.             this.heBack = this.backImage.getHeight(this);
  481.          }
  482.  
  483.          this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  484.          this.field_0 = this.buffer.getGraphics();
  485.          String fontName = ((Applet)this).getParameter("enter_text_font");
  486.          if (fontName == null) {
  487.             fontName = "TimesRoman";
  488.          }
  489.  
  490.          int style = 1;
  491.          String s = ((Applet)this).getParameter("enter_text_style");
  492.          if (s != null) {
  493.             if (s.equals("bold")) {
  494.                style = 1;
  495.             } else if (s.equals("italic")) {
  496.                style = 2;
  497.             } else if (s.equals("bold_italic")) {
  498.                style = 3;
  499.             } else {
  500.                style = 0;
  501.             }
  502.          }
  503.  
  504.          this.textFont = new Font(fontName, style, this.enterTextHeight);
  505.          this.field_0.setFont(new Font("TimesRoman", 1, this.enterTextHeight));
  506.          this.fm2 = this.field_0.getFontMetrics();
  507.          if (this.enterText != null) {
  508.             this.wiEnterText = this.fm2.stringWidth(this.enterText);
  509.          }
  510.  
  511.          this.field_0.setColor(this.starColor);
  512.          this.paintable = true;
  513.          this.firstime = false;
  514.       }
  515.  
  516.       this.field_4 = new int[this.number];
  517.       this.field_5 = new int[this.number];
  518.       this.step = new int[this.number];
  519.  
  520.       for(int i = 0; i < this.number; ++i) {
  521.          this.field_4[i] = (int)((double)this.field_2 * Math.random());
  522.          this.field_5[i] = (int)((double)this.field_3 * Math.random());
  523.          this.step[i] = (int)((double)this.step_mean * Math.random()) + 1;
  524.       }
  525.  
  526.       int c = 0;
  527.  
  528.       int m;
  529.       for(m = 0; (c = this.big_text.indexOf("#", c)) != -1; ++m) {
  530.          ++c;
  531.       }
  532.  
  533.       if (m != 0) {
  534.          this.index = new int[m];
  535.  
  536.          for(int var14 = 0; (c = this.big_text.indexOf("#", c)) != -1; ++var14) {
  537.             this.index[var14] = c++;
  538.          }
  539.  
  540.          this.text = this.big_text.substring(0, this.index[0]);
  541.          this.n_text = 0;
  542.       } else {
  543.          this.text = this.big_text;
  544.       }
  545.  
  546.       this.refonte(this.text_height);
  547.       this.decx = (this.field_2 - this.field_9.stringWidth(this.text)) / 2;
  548.       this.decy = (this.field_3 + this.field_9.getMaxAscent() - this.field_9.getMaxDescent()) / 2;
  549.       this.field_8 = 0;
  550.       this.decX = 0;
  551.       this.nextLetter();
  552.  
  553.       while(this.move) {
  554.          while(this.field_1) {
  555.             for(int i = 0; i < this.number; ++i) {
  556.                int[] var10000 = this.field_4;
  557.                var10000[i] += this.step[i];
  558.                if (this.field_4[i] > this.field_2) {
  559.                   this.field_4[i] = 0;
  560.                }
  561.             }
  562.  
  563.             ((Component)this).repaint();
  564.  
  565.             try {
  566.                Thread.sleep((long)this.pause);
  567.             } catch (InterruptedException var7) {
  568.                this.stop();
  569.             }
  570.  
  571.             if (!this.field_1) {
  572.             }
  573.          }
  574.  
  575.          try {
  576.             Thread.sleep(100L);
  577.          } catch (InterruptedException var5) {
  578.             this.stop();
  579.          }
  580.       }
  581.  
  582.    }
  583.  
  584.    public URL giveURL(String url) {
  585.       try {
  586.          if (url.toUpperCase().startsWith("HTTP")) {
  587.             return new URL(url);
  588.          } else if (url.toUpperCase().startsWith("FTP")) {
  589.             int p = url.indexOf(":");
  590.             int p2 = url.indexOf(":", p + 1);
  591.             if (p2 != -1) {
  592.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  593.             }
  594.  
  595.             p = url.indexOf("%40");
  596.             if (p != -1) {
  597.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  598.             }
  599.  
  600.             return new URL(url);
  601.          } else {
  602.             return new URL(((Applet)this).getCodeBase(), url);
  603.          }
  604.       } catch (MalformedURLException e) {
  605.          System.out.println(e);
  606.          return null;
  607.       }
  608.    }
  609.  
  610.    public void mouseClicked(MouseEvent e) {
  611.    }
  612.  
  613.    public void mouseEntered(MouseEvent e) {
  614.       if (this.enterText != null) {
  615.          this.isEnterTextEnabled = true;
  616.          ((Component)this).repaint();
  617.       }
  618.  
  619.       if (this.statusBarText != null) {
  620.          ((Applet)this).showStatus(this.statusBarText);
  621.       }
  622.  
  623.       if (this.enterSound != null) {
  624.          this.enterSound.play();
  625.       }
  626.  
  627.       if (this.link != null) {
  628.          ((Component)this).setCursor(new Cursor(12));
  629.       }
  630.  
  631.    }
  632.  
  633.    public void mouseExited(MouseEvent e) {
  634.       if (this.isEnterTextEnabled) {
  635.          this.isEnterTextEnabled = false;
  636.          ((Component)this).repaint();
  637.       }
  638.  
  639.       if (this.link != null) {
  640.          ((Component)this).setCursor(new Cursor(0));
  641.       }
  642.  
  643.    }
  644.  
  645.    public void mousePressed(MouseEvent e) {
  646.       if (this.clicSound != null) {
  647.          this.clicSound.play();
  648.       }
  649.  
  650.       if (this.link != null) {
  651.          String target = ((Applet)this).getParameter("target");
  652.          if (target == null) {
  653.             target = "_blank";
  654.          }
  655.  
  656.          URL u = this.giveURL(this.link);
  657.          ((Applet)this).getAppletContext().showDocument(u, target);
  658.       }
  659.  
  660.    }
  661.  
  662.    public void mouseReleased(MouseEvent e) {
  663.    }
  664. }
  665.